﻿@{
    ViewBag.Title = "代码生成";
    Layout = "~/Views/Shared/_Index.cshtml";
} 
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-info">
                <div class="box-body">
                    <div class="table-responsive">
                        <div class="btn-group-sm" id="toolbar" role="group"> 
                            <div class="col-sm-3 pull-right">
                                <div class="input-group input-group-sm">
                                    <input type="text" id="keyWord" col="KeyWord" class="form-control" placeholder="请输入数据表名称" />
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-primary btn-xs" onclick="searchGrid()"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <table id="gridTable" class="table table-hover table-striped text-nowrap">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("/Manage/Generator/GetPageListJson")';
        $('#gridTable').frameTable({
            url: queryUrl,
            sortName: 'TableName',
            sortOrder: "Asc",
            columns: [
                { field: 'Id', title: 'Id', visible: false },
                { field: 'TableName', title: '表名称', halign: "center", align: "center"},
                { field: 'TableKeyName', title: '主键名称', halign: "center", align: "center" },
                { field: 'TableKey', title: '主键字段', halign: "center", align: "center" },
                { field: 'TableCount', title: '记录数', halign: "center", align: "center" },
                { field: 'Remark', title: '备注', halign: "center", align: "center" },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a href="javascript:void(0);" class="btn btn-info btn-xs" onclick="showEntityForm(\'' + row.TableName + '\')"><i class="fa fa-database"></i> 实体生成</a> ');
                        actions.push('<a href="javascript:void(0);" class="btn btn-primary btn-xs" onclick="showGenerateForm(\'' + row.TableName + '\')"><i class="fa fa-bug"></i> 简单生成</a> ');
                        actions.push('<a href="javascript:void(0);" class="btn btn-warning btn-xs" onclick="showGenerateFormComplex(\'' + row.TableName + '\')"><i class="fa fa-copy"></i> 复杂生成</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $("#toolbar").getWebControls(pagination);
                return queryString;
            }
        });
    }
    function searchGrid() {
        $('#gridTable').ysTable('search');
    }
    function showGenerateForm(tableName) {
        frame.openDialog({
            title: "生成代码",
            content: '@Url.Content("/Manage/Generator/Form")' + '?tableName=' + tableName,
            height: ($(window).width() - 30) + 'px',
            width: ($(window).width() - 30) + 'px',
            btn: [],
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
    function showGenerateFormComplex(tableName) {
        frame.openDialog({
            title: "生成代码",
            content: '@Url.Content("/Manage/Generator/FormComplex")' + '?tableName=' + tableName,
            height: ($(window).height() - 20) + 'px',
            width: ($(window).width() - 20) + 'px',
            btn: [],
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function showEntityForm(tableName) {
        frame.openDialog({
            title: "生成实体",
            content: '@Url.Content("/Manage/Generator/FormEntity")' + '?tableName=' + tableName,
            width: "480px",
            height: "350px",
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
</script>